package org.iblink.core.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.iblink.core.domain.dao.CategoryDao;
import org.iblink.core.domain.model.Category;
import org.iblink.core.service.CategoryService;

/**
 * Implmentation class for managing categories.
 * 
 * @author tpares
 *
 */
public class CategoryServiceImpl implements CategoryService {

  private static final Logger logger = Logger.getLogger(CategoryServiceImpl.class.getName());
  private CategoryDao categoryDao;

  /**
   * {@inheritDoc}
   */
  @Override
  public void delete(Category category) {
    categoryDao.deleteCategory(category.getId());
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public List<Category> getSubCategories(Category category) {
    return categoryDao.getSubCategories(category.getId());
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void save(Category category) {
    categoryDao.saveCategory(category);
  }
  
  /**
   * {@inheritDoc}
   */
  @Override
  public List<Category> findAll() {
    return categoryDao.getCategories();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public List<Category> getRoots() {
    List<Category> temp = categoryDao.getRoots();
    int size = temp==null ? 0 : temp.size();
    logger.debug(size + " roots.");
    return categoryDao.getRoots();
  }

  /**
   * @return the categoryDao
   */
  public CategoryDao getCategoryDao() {
    return categoryDao;
  }

  /**
   * @param categoryDao the categoryDao to set
   */
  public void setCategoryDao(CategoryDao categoryDao) {
    this.categoryDao = categoryDao;
  }
}
